//1.导入vue 和 vuerouter 的包
import Vue from 'vue'
import VueRouter from 'vue-router'

//2.调用vue.use() 函数，把 VueRouter 安装为 Vue 的插件
//vue.use()函数的作用，就是来安装插件的
Vue.use(VueRouter)
const originalPush = VueRouter.prototype.push

VueRouter.prototype.push = function push(location) {
	return originalPush.call(this, location).catch(err => err)
}
//回头看第二步里的第3小步 =>  const router = new VueRouter()

const routes = [
	//重定向路由规则,防止用户进入空白页面
	{
		path: '/',
		redirect: '/index'
	},
	{
		path: '/index',
		name: 'index',
		meta: {
			title: '首页',
		},
		component: () => import('@/views/index/index.vue')
	},
	{
		path: '/indexTow',
		name: 'indexTow',
		meta: {
			title: '首页',
		},
		component: () => import('@/views/index/indexTow.vue')
	},
	{
		path: '/login',
		name: 'login',
		meta: {
			title: '登录',
		},
		component: () => import('@/views/login.vue')
	},
	{
		path: '/register',
		name: 'register',
		meta: {
			title: '注册',
		},
		component: () => import('@/views/register.vue')
	},
	{
		path: '/register',
		component: () => import('../views/register.vue')
	},
	{
		path: '/mine',
		name: 'mine',
		meta: {
			title: '我的',
		},
		component: () => import('@/views/user/index.vue')
	}, {
		path: '/profile',
		name: 'profile',
		meta: {
			title: '个人资料',
		},
		component: () => import('@/views/user/profile.vue')
	}, {
		path: '/mywallet',
		name: 'mywallet',
		meta: {
			title: '我的钱包',
		},
		component: () => import('@/views/user/mywallet.vue')
	}, {
		path: '/affiliate',
		name: 'affiliate',
		meta: {
			title: '推广分销',
		},
		component: () => import('@/views/user/affiliate.vue')
	}, {
		path: '/promotions',
		name: 'promotions',
		meta: {
			title: '优惠活动',
		},
		component: () => import('@/views/index/promotions.vue')
	}, {
		path: '/promotiondetail',
		name: 'promotiondetail',
		meta: {
			title: '优惠活动详情',
		},
		component: () => import('@/views/index/promotiondetail.vue')
	}, {
		path: '/helpcenter',
		name: 'helpcenter',
		meta: {
			title: '帮助中心',
		},
		component: () => import('@/views/user/helpcenter.vue')
	}, {
		path: '/helpcenterdetail',
		name: 'helpcenterdetail',
		meta: {
			title: '帮助中心详情',
		},
		component: () => import('@/views/user/helpcenterdetail.vue')
	},
	{
		path: '/personalMsg',
		name: 'personalMsg',
		meta: {
			title: '公告中心',
		},
		component: () => import('@/views/user/personalMsg.vue')
	}, {
		path: '/mission',
		name: 'mission',
		meta: {
			title: '任务日志',
		},
		component: () => import('@/views/user/mission.vue')
	}, {
		path: '/bankcards',
		name: 'bankcards',
		meta: {
			title: '银行卡管理',
		},
		component: () => import('@/views/user/bankcards.vue')
	}, {
		path: '/bindbank',
		name: 'bindbank',
		meta: {
			title: '银行卡管理',
		},
		component: () => import('@/views/user/bindbank.vue')
	},
	{
		path: '/changeWithdrawalPassword',
		name: 'changeWithdrawalPassword',
		meta: {
			title: '修改取款密码',
		},
		component: () => import('@/views/user/changeWithdrawalPassword.vue')
	},
	{
		path: '/changeLoginPassword',
		name: 'changeLoginPassword',
		meta: {
			title: '新密码',
		},
		component: () => import('@/views/user/changeLoginPassword.vue')
	},
	{
		path: '/vip',
		name: 'vip',
		meta: {
			title: 'vip',
		},
		component: () => import('@/views/user/vip.vue')
	},
	{
		path: '/vipRecord',
		name: 'vipRecord',
		meta: {
			title: 'VIP记录',
		},
		component: () => import('@/views/user/vipRecord.vue')
	},
	{
		path: '/playerInfo',
		name: 'playerInfo',
		meta: {
			title: '填写资讯',
		},
		component: () => import('@/views/user/playerInfo.vue')
	}, {
		path: '/deposit',
		name: 'deposit',
		meta: {
			title: '玩家充值',
		},
		component: () => import('@/views/user/deposit.vue')
	},
	{
		path: '/Charge',
		name: 'Charge',
		meta: {
			title: '充值',
		},
		component: () => import('@/views/user/Charge.vue')
	},
	{
		path: '/withdraw',
		name: 'withdraw',
		meta: {
			title: '提现',
		},
		component: () => import('@/views/user/withdraw.vue')
	},
	{
		path: '/finan-history',
		name: 'finan-history',
		meta: {
			title: '财务记录',
		},
		component: () => import('@/views/user/finan-history.vue')
	},
	{
		path: '/promotion',
		name: 'promotion',
		meta: {
			title: '财务记录详情',
		},
		component: () => import('@/views/user/promotion.vue')
	},
	{
		path: '/promotionTow',
		name: 'promotionTow',
		meta: {
			title: '财务记录详情',
		},
		component: () => import('@/views/user/promotionTow.vue')
	},
	{
		path: '/game-history',
		name: 'game-history',
		meta: {
			title: '游戏记录',
		},
		component: () => import('@/views/user/game-history.vue')
	},
	{
		path: '/personalMsgDeatil',
		name: 'personalMsgDeatil',
		meta: {
			title: '公告中心',
		},
		component: () => import('@/views/user/personalMsgDeatil.vue')
	},
	// {
	// 	path: '/sports',
	// 	name: 'sports',
	// 	meta: {
	// 		title: '体育',
	// 	},
	// 	component: () => import('@/views/type/sports.vue')
	// },
	{
		path: '/sports',
		name: 'sports',
		meta: {
			title: '体育',
		},
		component: () => import('@/views/type/newsports.vue')
	},
	{
		path: '/live',
		name: 'live',
		meta: {
			title: '真人',
		},
		component: () => import('@/views/type/newlive.vue')
	},
	{
		path: '/egame',
		name: 'egame',
		meta: {
			title: '电子游戏',
		},
		component: () => import('@/views/type/newegame.vue')
	},
	{
		path: '/chess',
		name: 'chess',
		meta: {
			title: '棋牌',
		},
		component: () => import('@/views/type/newchess.vue')
	},
	{
		path: '/mpg',
		name: 'mpg',
		meta: {
			title: '捕鱼',
		},
		component: () => import('@/views/type/newmpg.vue')
	},
	{
		path: '/animal',
		name: 'animal',
		meta: {
			title: '动物竞技',
		},
		component: () => import('@/views/type/animal.vue')
	},
	{
		path: '/esports',
		name: 'esports',
		meta: {
			title: '电竞',
		},
		component: () => import('@/views/type/esports.vue')
	},
	{
		path: '/vipRebates',
		name: 'vipRebates',
		meta: {
			title: '实时返水',
		},
		component: () => import('@/views/user/vipRebates.vue')
	}
]



const router = new VueRouter({
	routes,
	// scrollBehavior: () => ({ y: 0 }),
	scrollBehavior(to, from, savedPosition) { // 解决vue页面之间跳转，页面不是在顶部的问题
		return {
			x: 0,
			y: 0
		}
	},
	//routes 是一个数组，作用定义"hash 地址" 与 "组件" 之间的对应关系

})
// router.beforeEach((to, from, next) => {
// 	// 让页面回到顶部
// 	document.documentElement.scrollTop = 0;
// 	next();
// });
// router.beforeEach((to, from, next) => {
// 	document.body.scrollTop = 0;
// 	document.documentElement.scrollTop = 0;
// 	window.pageYOffset = 0;
// 	next();
// });


//4.向外共享路由的实例对象
export default router